var fileManagerLoaded = false;
var fileManagerMinMax = false;
var UserControlPanelLoaded = false;
var UserControlPanelMinMax = false;
var RSSMinMax = false;
var RSSLoaded = false;
function fileManagerClicked() {
    if (fileManagerLoaded) {
        if (!fileManagerMinMax) {
            $('#FileManager').hide();
            fileManagerMinMax = true
        }

        else {
            $('#FileManager').show();
            fileManagerMinMax = false;
        }
    }
    else {
        fileManagerLoaded = true;
        var script = "<script type=\"text/javascript\">"
+ "        $(ComponentResizableDragable('FileManager'));\n"
+ " </script>";
        var fileManagerHtml = '<div id="FileManager"  class="Frame ui-resizable ui-draggable">'
    + '<div id="outerBorder"><div id="fileManagerHeader"  class="IconBox">'
        + '<a href="#" onclick="fileMangerClose()" onmouseover="fileManagerCloseMouseOver()" onmouseout="fileManagerCloseMouseOut()"><img class ="closeIcon" src="../TemplateImages/FileManager/blue_close.png" alt="close" title="Close" /></a>'
        + '<a href="#" onclick="fileManagerMax()" onmouseover="fileManagerMaximizeMouseOver()" onmouseout="fileManagerMaximizeMouseOut()"><img class ="maximizeIcon" src="../TemplateImages/FileManager/maximize.png" alt="max" title="Maximize" /></a>'
        + '<a href="#" onclick="fileMangerMin()" onmouseover="fileManagerMinimizeMouseOver()" onmouseout="fileManagerMinimizeMouseOut()"><img class ="minimizeIcon" src="../TemplateImages/FileManager/gray_minimize.png" alt="min" title="Minimize"/></a>'
     + '</div>'
     + '<div id="fileManagerFrame" style="width:100% ;height:500px;">'
                    + '<iframe scrolling="NO" src="FileManager.aspx" style="width:100%;height:100%;"></iframe></div></div>'
 + '</div>';

        $('#desktopArea').prepend(script + fileManagerHtml);
        $("#FileManager").bind("resizestop", fileManagerResize);
    }
}
function ComponentResizableDragable(id) { 

          $("#"+id).resizable({
            animate: true,
            minHeight: 250,
            minWidth: 200,
            helper: "ui-resizable-helper",
            containment: "#desktopArea"
        });
           $("#"+id).draggable();
        
}
/* ==== JQuery resizable icon ====*/
function fileManagerResize(event, ui) {
    var height = ui.size.height;
    $('#fileManagerFrame').height(height-33);
    $('#outerBorder').height(height);
    var width = ui.size.width;
    $('.Main').width(width);
}

/* ==== File manager close icon ====*/
function fileMangerClose() {
    $('#FileManager').replaceWith('');
    fileManagerLoaded = false;
    fileManagerMinMax = false;
    var postData = 'ACTIONTYPE=FILEMANAGER&ACTION=CLOSE&';
    $.ajax({
        url: 'AjaxController.ashx',
        type: 'post',
        data: postData,
        success: function (rhtml) { }

    });
}
function fileManagerCloseMouseOver() {
    $('.closeIcon').attr("src", "../TemplateImages/FileManager/red_close.png");
}
function fileManagerCloseMouseOut() {
    $('.closeIcon').attr("src", "../TemplateImages/FileManager/blue_close.png");
}

/* ==== File manager maximize icon ====*/
function fileManagerMax() {
    $("#FileManager").toggleClass("Maximize");
    $('#FileManager .Main').css("width", "84%");
    $('#FileManager .Main').css("height", "96%");
}
function fileManagerMaximizeMouseOver() {
    $('.maximizeIcon').attr("src", "../TemplateImages/FileManager/maximize_Hover.png");
    $('.maximizeIcon').css("height", "21px");
}
function fileManagerMaximizeMouseOut() {
    $('.maximizeIcon').attr("src", "../TemplateImages/FileManager/maximize.png");
    $('.maximizeIcon').css("height", "18px");
}

/*==== File manager minimize icon ====*/
function fileMangerMin() {
    $('#FileManager').hide();
    fileManagerMinMax = true;
}
 
function fileManagerMinimizeMouseOver() {
    $('.minimizeIcon').attr("src", "../TemplateImages/FileManager/minimize_Hover.png");
    $('.minimizeIcon').css("height", "20px");
    $('.maximizeIcon').css("width", "20px");
}
function fileManagerMinimizeMouseOut() {
      $('.minimizeIcon').attr("src", "../TemplateImages/FileManager/gray_minimize.png");
  }


  ///////////////////////////////////
  function UserControlPanelClick() {
      if (UserControlPanelLoaded) {
          if (!UserControlPanelMinMax) {
              $('#UserControlPanel').hide();
              UserControlPanelMinMax = true
          }

          else {
              $('#UserControlPanel').show();
              UserControlPanelMinMax = false;
          }
      }
      else {
          UserControlPanelLoaded = true;

          var UsrControl = '<div id="UserControlPanel"  class="ui-draggable"  style="width: 1011px;z-index:1000;left:50px;top:100px">'
    + '<div id=""  class="UserControllerHeader">'
        + '<a href="#" onclick="UserControlPanelClose()" onmouseover="fileManagerCloseMouseOver()" onmouseout="fileManagerCloseMouseOut()"><img class ="closeIcon" src="../TemplateImages/FileManager/blue_close.png" alt="close" title="Close" /></a>'
     + '</div>'
     + '<div id="" style="width:100% ;height:520px;">'
                    + '<iframe scrolling="NO" src="User-Settings.aspx" style="width:100%;height:100%;"></iframe></div>'
 + '</div>';

          $('#desktopArea').prepend( UsrControl);
          $("#UserControlPanel").draggable();
      }
  }

  function UserControlPanelClose() {
      $('#UserControlPanel').replaceWith('');
      UserControlPanelLoaded = false;
  }

  ///////////////////////////////////////////////////////////
  function RSSClick() {
      if (RSSLoaded) {
          if (!RSSMinMax) {
              $('#RSSPanel').hide();
              RSSMinMax = true
          }

          else {
              $('#RSSPanel').show();
              RSSMinMax = false;
          }
      }
      else {
          RSSLoaded = true;

          var RSS = '<div id="RSSPanel"  class=""  style="width: 1011px;z-index:1000;left:50px;top:100px">'
    + '<div id=""  class="UserControllerHeader" style="margin-left:0px;width:100%">'
        + '<a href="#" onclick="RSSPanelClose()" onmouseover="fileManagerCloseMouseOver()" onmouseout="fileManagerCloseMouseOut()"><img class ="closeIcon" src="../TemplateImages/FileManager/blue_close.png" alt="close" title="Close" /></a>'
     + '</div>'
     + '<div id="" style="width:100% ;height:600px;">'
                    + '<iframe scrolling="YES" src="RSS.aspx" style="width:100%;height:100%;"></iframe></div>'
 + '</div>';

          $('#desktopArea').prepend(RSS);
          $("#RSSPanel").draggable();
      }
  }

  function RSSPanelClose() {
      $('#RSSPanel').replaceWith('');
      RSSLoaded = false;
  }